package com.test.cordova.mvp.base;

import java.lang.ref.WeakReference;

/**
 * Created by Administrator on 2019/2/22 0022.
 */

public abstract class BasePresenter<M extends IModel,V extends IView> implements IPresenter<M,V> {

    protected M model;
    private WeakReference<V> weakReferenceV ;

    @Override
    public void registerModel(M model) {
        this.model = model;
    }

    @Override
    public void registerView(V view) {
        weakReferenceV = new WeakReference<V>(view);
    }

    @Override
    public V getView() {
        return weakReferenceV!=null?weakReferenceV.get():null;
    }

    @Override
    public void destroy() {
        if (weakReferenceV != null) {
            weakReferenceV.clear();
            weakReferenceV = null;
        }
        onViewDestroy();
    }

    public abstract void onViewDestroy();
}
